/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.woundedwolf.android.tumbleweed.examples;

import com.woundedwolf.android.tumbleweed.AbstractGame;
import com.woundedwolf.android.tumbleweed.Engine;
import com.woundedwolf.android.tumbleweed.Particle;
import com.woundedwolf.android.tumbleweed.Pixel;
import com.woundedwolf.android.tumbleweed.renderables.Pixels;
import java.util.ArrayList;
import java.util.Random;

/**
 *
 * @author FlameDuck
 */
public class PixelField extends AbstractGame
{
	private Pixels pixels;
	private Random random;

	public PixelField(Engine engine)
	{
		super(engine);
		pixels = new Pixels(256);
		addRenderable(pixels);
		random = new Random(System.currentTimeMillis());
	}

	public void updateGame()
	{
		float xPos = random.nextFloat()*engine.graphicsWidth();
		float yPos = random.nextFloat()*engine.graphicsHeight();

		Particle p = new Particle( xPos, yPos, 200);
		pixels.addPixel(p);
                
		for (Pixel pixel : pixels.getPixels())
		{
			if (pixel instanceof Particle)
			{
				((Particle)pixel).update();
				pixels.updatePixel(pixel);
				if (((Particle)pixel).isDead())
					pixels.removePixel(pixel);
			}
		}
	}
}
